/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package vip.xiaonuo.biz.modular.edumaterialcate.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.biz.modular.educoursecate.entity.EduCourseCate;
import vip.xiaonuo.biz.modular.educoursecate.param.EduCourseCatePageParam;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.biz.modular.edumaterialcate.entity.EduMaterialCate;
import vip.xiaonuo.biz.modular.edumaterialcate.param.EduMaterialCateAddParam;
import vip.xiaonuo.biz.modular.edumaterialcate.param.EduMaterialCateEditParam;
import vip.xiaonuo.biz.modular.edumaterialcate.param.EduMaterialCateIdParam;
import vip.xiaonuo.biz.modular.edumaterialcate.param.EduMaterialCatePageParam;
import vip.xiaonuo.biz.modular.edumaterialcate.service.EduMaterialCateService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.io.IOException;
import java.util.List;

/**
 * 素材分类控制器
 *
 * @author 周弘杰
 * @date  2025/07/06 05:24
 */
@Tag(name = "素材分类控制器")
@RestController
@Validated
public class EduMaterialCateController {

    @Resource
    private EduMaterialCateService eduMaterialCateService;


    /**
     * 获取素材分类树
     *
     * @author 周弘杰
     * @date 2025/06/28 09:42
     */
    @Operation(summary = "获取课程分类树")
//    @SaCheckPermission("/biz/edumaterialcate/tree")
    @GetMapping("/biz/edumaterialcate/tree")
    public CommonResult<List<EduMaterialCate>> tree(EduMaterialCatePageParam eduMaterialCatePageParam) {
        List<EduMaterialCate> cateTree = eduMaterialCateService.tree(eduMaterialCatePageParam);
        return CommonResult.data(cateTree);
    }



    /**
     * 添加素材分类
     *
     * @author 周弘杰
     * @date  2025/07/06 05:24
     */
    @Operation(summary = "添加素材分类")
    @CommonLog("添加素材分类")
    @SaCheckPermission("/biz/edumaterialcate/add")
    @PostMapping("/biz/edumaterialcate/add")
    public CommonResult<String> add(@RequestBody @Valid EduMaterialCateAddParam eduMaterialCateAddParam) {
        eduMaterialCateService.add(eduMaterialCateAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑素材分类
     *
     * @author 周弘杰
     * @date  2025/07/06 05:24
     */
    @Operation(summary = "编辑素材分类")
    @CommonLog("编辑素材分类")
    @SaCheckPermission("/biz/edumaterialcate/edit")
    @PostMapping("/biz/edumaterialcate/edit")
    public CommonResult<String> edit(@RequestBody @Valid EduMaterialCateEditParam eduMaterialCateEditParam) {
        eduMaterialCateService.edit(eduMaterialCateEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除素材分类
     *
     * @author 周弘杰
     * @date  2025/07/06 05:24
     */
    @Operation(summary = "删除素材分类")
    @CommonLog("删除素材分类")
    @SaCheckPermission("/biz/edumaterialcate/delete")
    @PostMapping("/biz/edumaterialcate/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<EduMaterialCateIdParam> eduMaterialCateIdParamList) {
        eduMaterialCateService.delete(eduMaterialCateIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取素材分类详情
     *
     * @author 周弘杰
     * @date  2025/07/06 05:24
     */
    @Operation(summary = "获取素材分类详情")
    @SaCheckPermission("/biz/edumaterialcate/detail")
    @GetMapping("/biz/edumaterialcate/detail")
    public CommonResult<EduMaterialCate> detail(@Valid EduMaterialCateIdParam eduMaterialCateIdParam) {
        return CommonResult.data(eduMaterialCateService.detail(eduMaterialCateIdParam));
    }

    /**
     * 下载素材分类导入模板
     *
     * @author 周弘杰
     * @date  2025/07/06 05:24
     */
    @Operation(summary = "下载素材分类导入模板")
    @GetMapping(value = "/biz/edumaterialcate/downloadImportTemplate", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public void downloadImportTemplate(HttpServletResponse response) throws IOException {
        eduMaterialCateService.downloadImportTemplate(response);
    }

    /**
     * 导入素材分类
     *
     * @author 周弘杰
     * @date  2025/07/06 05:24
     */
//    @Operation(summary = "导入素材分类")
//    @CommonLog("导入素材分类")
//    @SaCheckPermission("/biz/edumaterialcate/importData")
//    @PostMapping("/biz/edumaterialcate/importData")
    public CommonResult<JSONObject> importData(@RequestPart("file") MultipartFile file) {
        return CommonResult.data(eduMaterialCateService.importData(file));
    }

    /**
     * 导出素材分类
     *
     * @author 周弘杰
     * @date  2025/07/06 05:24
     */
//    @Operation(summary = "导出素材分类")
//    @SaCheckPermission("/biz/edumaterialcate/exportData")
//    @PostMapping(value = "/biz/edumaterialcate/exportData", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
    public void exportData(@RequestBody List<EduMaterialCateIdParam> eduMaterialCateIdParamList, HttpServletResponse response) throws IOException {
        eduMaterialCateService.exportData(eduMaterialCateIdParamList, response);
    }
}
